****************co2 and financial development************
//set the data path
cd "E:\data\cooperation\finance_research\innovation\data"
use co2_finance,clear  //load the data

*************
bysort province: egen energy_d=mean(fossild1)

tabstat energy_d, stat(p50)
label var energy_d "The mean of fossil energy dependence"

gen energy_dum=0
replace energy_dum=1 if energy_d>0.721395
gen fscale2= fscale^2
gen l_per_gdp=log(per_gdp)
gen l_population=log(population)
gen l_fdi=log(fdi)
//set the labels of the variables
label var per_co2 "CO2 emissions per capital"
label var fscale "Financial scale (%)"
label var tech "Technological innovation"
label var env_regul "Environment regulation"
label var l_per_gdp "The log of real GDP per capital"
label var l_population "The log of population (people per sq. km of land area)"
label var stru_2 "Proportion of secondary industry  (%)"
label var WW  "Industrial wastewater emissions per capita"
label var gdp_a  "The growth rate of real GDP"
label var internet_use  "Internet penetration"
label var cpi  "Consumer Price Index"
label var fscale2  "The square of financial scale"
label var l_fdi "The log of FDI"
label var fossild1 "Fossil energy dependence"
label var  feffic "Financial efficiency (%)"
//set the panel data

xtset id year


*****************************data description**********************
sum per_co2 WW fscale feffic l_per_gdp  tech  gdp_a cpi l_population l_fdi internet_use  env_regul   stru_2 fossild1  

des per_co2 WW fscale feffic l_per_gdp tech  gdp_a cpi l_population l_fdi internet_use  env_regul   stru_2 fossild1 


//statisitcal anlysis
 xtunitroot fisher per_co2, dfuller lags(1) drift
 xtunitroot fisher fscale, dfuller lags(1) drift
  xtunitroot fisher fscale, dfuller lags(1) drift
collin    fscale effict l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2
des   fscale effict l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2


sum feffic


//besic result
gen gdp_2=l_per_gdp^2
gen feffic2=feffic^2

xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2,fe
est store reg1
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2,re
est store reg2
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 i.year,fe
est store reg3
xtreg per_co2  fscale fscale2  l_per_gdp      gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2,fe
est store reg4
xtreg per_co2  feffic  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2,fe
est store reg5
xtreg per_co2  feffic  feffic2 l_per_gdp      gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2,fe
est store reg6
esttab reg1 reg2 reg3 reg4 reg5 reg6 , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fscale  fscale2 feffic  feffic2 l_per_gdp    gdp_a   cpi l_population l_fdi   env_regul  stru_2  _cons   ) ///
legend label varwidth(60) varlabels(_cons Constant) mtitles("OLS" "RE" "FE" "FE" "FE" "FE") /// 
stats(N r2, fmt(0 4) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)

hausman reg1 reg2,sigmamore

//the margin effect of financial scale and financial efficiency
xtreg per_co2  c.effict##c.effict  l_per_gdp gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2, fe
margins,dydx(effict) at(effict=(0.5(0.5)15)) atmeans
marginsplot

xtreg per_co2  c.fscale##c.fscale  l_per_gdp gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2, fe
margins , dydx(fscale) at(fscale=(0(0.5)10)) 
marginsplot

graph combine  Graph1.gph Graph2.gph


//The moderating effect of technological innovation
bysort province: egen tech_d=mean(tech)

tabstat tech_d, stat(p50 mean)

gen tech_d_dum=0
replace tech_d_dum=1 if tech_d<=2.231667
gen fscale_techd_d=fscale*-tech_d_dum

xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if tech_d_dum==0,fe
est store reg1
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if tech_d_dum==1,fe
est store reg2
xtreg per_co2  fscale fscale_techd_d  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  ,fe
est store reg3

tabstat tech, stat(  p50  mean)

gen tech_dum=0
replace tech_dum=1 if tech<=1.705
gen fscale_tech=fscale*tech_dum

xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if tech_dum==0,fe
est store reg4
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if tech_dum==1,fe
est store reg5
xtreg per_co2  fscale fscale_tech tech_dum l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg6
esttab reg1 reg2 reg3  reg4 reg5 reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep(fscale fscale_techd_d   tech_dum   _cons) ///
 mtitles("High innovation" "Low innovation" "All data" "tech>=1.705" "tech<1.705" "All data") ///
legend label varwidth(60) varlabels(_cons Constant) /// 
stats(N r2, fmt(0 4) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01) 


//The moderating effect of fossil energy dependence
tabstat fossild1, stat(p50 mean)

gen dum_energy=0
replace dum_energy=1 if fossild1>.7319233
gen f_dum2=-fscale*energy_dum 
gen   f_dum1=-fscale*dum_energy

xtreg per_co2  fscale   l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if energy_dum==0 ,fe
est store reg1
xtreg per_co2  fscale  fscale2 l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if energy_dum==0 ,fe
est store reg2
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2  if energy_dum==1 ,fe
est store reg3
xtreg per_co2  fscale f_dum2 energy_dum  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg4


xtreg per_co2  fscale   l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 if dum_energy==0,fe
est store reg5
xtreg per_co2  fscale  fscale2 l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 if dum_energy==0,fe
est store reg6
xtreg per_co2  fscale  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 if dum_energy==1,fe
est store reg7
xtreg per_co2  fscale f_dum1 dum_energy  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg8
esttab  reg5 reg6 reg7 reg8 reg1 reg2 reg3 reg4  , cells(b(star fmt(4)) t(par fmt(2))) /// 
keep ( fscale   f_dum1  f_dum2  dum_energy _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 4) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  


//dual moderating effect
 gen f_dum3=fscale_tech*dum_energy
gen f_dum4=fscale_tech*energy_dum
gen f_dum5=fscale_techd_d*dum_energy
gen f_dum6=fscale_techd_d*energy_dum

xtreg per_co2  fscale f_dum3 f_dum1 fscale_tech dum_energy tech_dum  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg1

xtreg per_co2  fscale f_dum4 f_dum2 fscale_tech  tech_dum  l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg2

xtreg per_co2  fscale f_dum5 f_dum1  fscale_techd_d    l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg3

xtreg per_co2  fscale f_dum6 f_dum2  fscale_techd_d    l_per_gdp     gdp_a cpi l_population  internet_use  env_regul    l_fdi stru_2 ,fe
est store reg4

esttab  reg1 reg2 reg3 reg4, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fscale f_dum3 f_dum2 f_dum1 f_dum4 f_dum5 f_dum6  fscale_tech dum_energy   tech_dum _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("Low" "High" "All" "Low" "High" "All") /// 
stats(N r2, fmt(0 4) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  



*****************************************robust test********************
reg WW fscale  l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2   
est store reg1
xtgls WW  fscale  l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  i.year, panels(hetero)
est store reg2
xtreg WW  fscale  l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2  ,fe
est store reg3
xtreg WW  fscale l_per_gdp   gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2 ,re
est store reg4
xtivreg per_co2  (fscale= fdepth_loan L.fscale) l_per_gdp   gdp_a cpi l_population l_fdi internet_use  env_regul tech stru_2  ,fe
xtoverid
dmexogxt
est store reg6
esttab reg1 reg2 reg3 reg4  reg6, cells(b(star fmt(4)) t(par fmt(2))) /// 
keep (fscale   l_per_gdp  gdp_a cpi l_population l_fdi internet_use  env_regul  tech stru_2 _cons) ///
legend label varwidth(50) varlabels(_cons Constant) mtitles("ols" "FGLS" "FE" "RE" "FE") /// 
stats(N r2, fmt(0 4) label(Observation R-squared )) star(* 0.1 ** 0.05 *** 0.01)  /*table 3*/

hausman reg3 reg4





